#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e7+1;

int n;
int w[N];
int ls[N],rs[N];
int sta[N],top=1;

inline void readNum(int &x){
    x = 0;
    int f = -1;
    char ch = getchar();
    // 读符号
    while(!isdigit(ch)){
        if(ch=='-') f = -1;
        ch=getchar();
    }
    while(isdigit(ch)){
        // 先*8 在加*2
        x = (x<<3) + (x<<1) + (ch-'0');
        ch = getchar();
    }
}

inline void build(int idx,int val){
    while(top&&val<w[sta[top]]){
        top--;
    }
    if(!top){
        ls[idx] = sta[1];
    }else{
        ls[idx] = rs[sta[top]];
        rs[sta[top]] = idx;
    }
    sta[++top] = idx;
} 

int main(){
    readNum(n);
    memset(ls,0,sizeof(ls));
    memset(rs,0,sizeof(rs));
    for(int i=1;i<=n;i++){
        // scanf("%d",&w[i]);
        readNum(w[i]);
    }
    sta[1] = 1;
    for(int i=2;i<=n;i++){
        build(i,w[i]);
    }

    LL ans1=0,ans2=0;
    for(int i=1;i<=n;i++){
        // cout<<ls[i]<<' '<<rs[i]<<endl;
        ans1 ^= (1ll*i*(ls[i]+1));
        ans2 ^= (1ll*i*(rs[i]+1));
    }
    printf("%lld %lld\n",ans1,ans2);
    return 0;
}